<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<h1>用户登录</h1>
<hr>
<div>
    <form id="regForm" action="#" method="post">
        <table>
            <tr>
                <td class="title">用户名：</td>
                <td><input type="text" id="username" name="username"/></td>
            </tr>
            <tr>
                <td class="title">密码：</td>
                <td><input type="password" id="password" name="password"/></td>
            </tr>

            <tr>
                <td colspan="2" style="text-align: center">
                    <button type="button" onclick="doLogin()">登录</button>
                </td>
            </tr>
        </table>
    </form>
</div>

<script>


    function doLogin() {
        let username = $("#username").val();
        let password = $("#password").val();

        console.log('执行用户登录,username='+username+",password="+password);

        //发送ajax请求

        $.ajax({
            url: 'http://localhost:8080/ssmdemo/users/auth?username='+username+'&password='+password,
            type: 'get',
            async: true,
            success: function (resp) {
                console.log(resp);
                if(resp.code===200){
                    console.log("登录成功用户："+JSON.stringify(resp.data));
                    alert('登录成功！');
                }else{
                    alert("登录失败！");
                }
            }
        });
    }
</script>

</body>
</html>
